//
//  ReminderMainVC.m
//  Chat
//
//  Created by 任伟 on 16/3/7.
//  Copyright © 2016年 任伟. All rights reserved.
//

#import "ReminderMainVC.h"
#import "RWRemindHeadView.h"
#import "RWReminderMainCell.h"

@interface ReminderMainVC () <UITableViewDataSource,UITableViewDelegate,ReminderMainCellDelegate>

@property (nonatomic, strong) RWRemindHeadView  *headView;
@property (nonatomic, strong) UITableView       *endView;
@property (nonatomic, strong) UILabel           *noDataLabel;
@property (nonatomic, strong) NSMutableArray    *reminderMArr;

@end

@implementation ReminderMainVC

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self creatBasicSetUp];
    [self creatHeadView];
    [self creatEndView];

}

- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    self.navigationController.navigationBar.translucent = YES;
    
    [self reloadData];
}

- (void)viewDidAppear:(BOOL)animated {

    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {

    [super viewWillDisappear:animated];
    self.tabBarController.tabBar.hidden = NO;
    self.tabBarController.tabBar.translucent = NO;
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBar.translucent = NO;
    
}

#pragma mark - 设置界面
/// 设置基本界面
- (void)creatBasicSetUp {
    
    self.title = @"提醒";
    self.view.backgroundColor = [UIColor whiteColor];
    self.reminderMArr = [NSMutableArray array];
    
}

/// 创建顶部的view
- (void)creatHeadView {

    self.headView = [[RWRemindHeadView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth/2)];
    self.headView.backgroundColor = RGBACOLOR(241, 242, 243, 1);
    self.headView.bulbImage.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionDo:)];
    [self.headView.bulbImage addGestureRecognizer:tapGesture];
    [self.view addSubview:self.headView];
    
    // 手势
    UISwipeGestureRecognizer *slideUP = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(reportVerticalSwipe:)];
    slideUP.direction = UISwipeGestureRecognizerDirectionDown;
    [self.headView addGestureRecognizer:slideUP];
    
    UISwipeGestureRecognizer *slideDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(reportVerticalSwipe:)];
    slideDown.direction = UISwipeGestureRecognizerDirectionUp;
    [self.headView addGestureRecognizer:slideDown];
}

/// 创建底部的view
- (void)creatEndView {

    self.endView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.headView.top+self.headView.height, ScreenWidth, ScreenHeight-(self.headView.top+self.headView.height)-TabbarHeight) style:(UITableViewStyleGrouped)];
    self.endView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.endView.backgroundColor = RGBACOLOR(188, 232, 252, 1);
    self.endView.delegate = self;
    self.endView.dataSource = self;
    [self.view addSubview:self.endView];
    
    self.noDataLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 100, ScreenWidth - 30, 40)];
    self.noDataLabel.font = [UIFont systemFontOfSize:14.0f];
    self.noDataLabel.textColor = RGBACOLOR(158, 175, 183, 1);
    self.noDataLabel.textAlignment = NSTextAlignmentCenter;
    self.noDataLabel.numberOfLines = 0;
    self.noDataLabel.text = @"繁忙生活，点滴精彩，建个提醒不会错过哦~";
    [self.endView addSubview:self.noDataLabel];
}

#pragma mark - 刷新数据
- (void)reloadData {

}

#pragma mark - TableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString * cellidentifier = @"HEReminderTimeCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellidentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellidentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor clearColor];
    }
    
    cell.textLabel.text = @"ddffa";
    
    return cell;
}

#pragma mark - 监听方法
/// 单击手势
- (void)actionDo:(id)sender {

    [self downSlide];
}


#pragma mark - 响应事件
// 拖拽手势
- (void)reportVerticalSwipe:(UISwipeGestureRecognizer *)recognizer {

    if (recognizer.direction == UISwipeGestureRecognizerDirectionDown) {
        
        [self downSlide];
        NSLog(@"下滑");
    } else if (recognizer.direction == UISwipeGestureRecognizerDirectionUp) {
    
        [self upSlide];
        NSLog(@"上滑");
    }
}

/// 背景图向上滑动
- (void)upSlide {

    if (self.headView.height != ScreenWidth/2) {
        [UIView animateWithDuration:0.5
                              delay:0
                            options:UIViewAnimationOptionTransitionFlipFromLeft
                         animations:^{
                             
                             [self.headView setFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth/2)];
                             [self.headView packUpView];
                             [self.endView setFrame:CGRectMake(0, self.headView.top+self.headView.height, ScreenWidth, ScreenHeight - (self.headView.top+self.headView.height) - TabbarHeight)];
                         }
                         completion:^(BOOL finished) {
                             
                         }];
    }
}

/// 背景图向上滑动
- (void)downSlide {

    if (self.headView.height == ScreenWidth/2) {
        [UIView animateWithDuration:0.5
                              delay:0
                            options:UIViewAnimationOptionTransitionFlipFromLeft
                         animations:^{
                             
                             [self.headView setFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - TabbarHeight)];
                             [self.headView openView];
                             [self.endView setFrame:CGRectMake(0, self.headView.top + self.headView.height, ScreenWidth, ScreenHeight - (self.headView.top + self.headView.height) - TabbarHeight)];
                         } completion:^(BOOL finished) {
                             
                         }];
    }
}

@end
